package net.esj.basic.plugins;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.annotation.PostConstruct;

import net.esj.basic.core.engine.config.PropertiesConfiguration;
import net.esj.basic.core.engine.resource.ApplicationResourceBundler;
import net.esj.basic.core.engine.resource.ResourceBundler;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public abstract class PluginConfiguration implements ApplicationContextAware {
	
	private ApplicationContext applicationContext;

	protected ResourceBundler messageBundler;
	
	protected PropertiesConfiguration setting;
	
	public abstract String getResourceFileName();
	
	public abstract String getSettingName();
	
	public PluginConfiguration() {
		super();
		//setting = new PropertiesConfiguration(getSettingName());
		messageBundler = new ApplicationResourceBundler(getResourceFileName());
		//postConstruct();
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext =applicationContext;
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}
	
	public Object getProperty(String key){
		if(setting!=null){
			return setting.getProperty(key);
		}
		return "";
	}
	
	public String getMessage(String key,Locale locale){
		ResourceBundle rb = messageBundler.getResourceBundle(locale);
		if(rb!=null){
			return rb.getString(key);
		}
		return "";
	}
	
	@PostConstruct
	protected void postConstruct() {
	}
}
